const express=require('express');
const app=express();

// app.use((req,res,next)=>{
//     console.log('normal middleware01');
//     next();
// }),
// app.use((req,res,next)=>{
//     console.log('normal middleware02');
//     next();
// }),
// app.get('/home',(req,res,next)=>{
//     console.log('/home get middleware01');
//     next();
// },
// (req,res,next)=>{
//     console.log('/home get middleware02');
//     res.end('GET /home response completed');
// });

    app.use(express.json());
    app.post('/login', (req, res, next) => {
        const { username, password } = req.body;
        console.log(req.body);
    req.on('end',()=>{
        if(username === 'gkd' && password === '123456'){
            res.end('登录成功, 欢迎回来~');
        }else{
            res.end('登录失败, 请检测账号和密码是否正确~');
        }
    })
});
app.post('/register',(req,res,next)=>{
        const{username}=req.body;
        console.log(req.body);
    const existingUsers=['existinguser'];
        if(existingUsers.includes(username)){
            res.end('注册失败, 您输⼊的⽤户名被注册~');
        }else{
            res.end('注册成功, 开始你的旅程~');
        }
    });

// app.use((req,res,next)=>{
//     console.log('normal middleware03');
//     next();
// });
// app.use((req,res,next)=>{
//     console.log('normal middleware04');
//     next();
// });

app.listen(9000,()=>{
    console.log('Express服务器启动成功');
});





